// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: implementation of CXFormsParseMessage.
//   $Id$


#include "stdafx.h"
#include "ActionMessage.h"
#include "parseMessage.h"
#include "tags.h"

CMapStringToPtr CXFormsParseMessage::sm_LevelTokens;
HANDLE CXFormsParseMessage::sm_hLevelTokensMutex = 0;

CXFormsParseMessage::CXFormsParseMessage(CImplActionMessage* pImpl)
	: CXFormsParseAction(static_cast<CImplAction*>(pImpl))
{
	if(!sm_hLevelTokensMutex)
		sm_hLevelTokensMutex = CreateMutex(0, FALSE, _T("Local\\XFormsParseMessageLevelTokensMutex"));

	WaitForSingleObject(sm_hLevelTokensMutex, INFINITE);

	try
	{
		if(sm_LevelTokens.IsEmpty())
		{
			//fill the tokenising map only if it has not already been done.
			sm_LevelTokens.SetAt(ATTR_LEVEL_MODAL,(LPVOID)CImplActionMessage::ELevels::modal);
			sm_LevelTokens.SetAt(ATTR_LEVEL_MODELESS,(LPVOID)CImplActionMessage::ELevels::modeless);
			sm_LevelTokens.SetAt(ATTR_LEVEL_EPH,(LPVOID)CImplActionMessage::ELevels::ephemeral);
		}	

		m_psImplContent = &pImpl->m_sTextContent;
		
		//maybe don't bother with a map, too much baggage.
		//	this won't change during the execution of the 
		//	program, so I can rely on the position within
		//	the array to give me a unique id.
		addAttributeCheck(ATTR_LEVEL,(LPVOID*)&pImpl->m_eLevel,&sm_LevelTokens);
		//action attributes (easier than multiple inheritance)
		addAttributeCheck(ATTR_EVENT, &pImpl->m_sEvent);
		addAttributeCheck(ATTR_OBSERVER, &pImpl->m_sObserver);
		addAttributeCheck(ATTR_MODEL, &pImpl->m_sModel);
		addAttributeCheck(ATTR_REF, &pImpl->m_sRef);
		addAttributeCheck(ATTR_BIND, &pImpl->m_sBind);
		m_bCheckElements = false;
	}
	catch(...)
	{
	}

	ReleaseMutex(sm_hLevelTokensMutex);
};